package ustc.xiaoyang.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import ustc.xiaoyang.pojo.Emp;
import ustc.xiaoyang.pojo.Result;
import ustc.xiaoyang.pojo.dto.EmpPageQueryDTO;
import ustc.xiaoyang.service.EmpService;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    private EmpService empService;
    public EmpController(EmpService empService) {
        this.empService = empService;
    }

    @GetMapping
    public Result pageList(EmpPageQueryDTO empPageQueryDTO){
        log.info("分页查询,查询参数：{}", empPageQueryDTO);
        return Result.success(empService.pageList(empPageQueryDTO));
    }
    @PostMapping
    public Result add(@RequestBody Emp emp){
        log.info("添加员工,员工信息：{}", emp);
        empService.add(emp);
        return Result.success();
    }
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Integer> ids){
        log.info("删除员工,员工ID：{}", ids);
        empService.deleteByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据id查询员工：{}",id);
        return Result.success(empService.getById(id));
    }

    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工，员工信息：{}", emp);
        empService.update(emp);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(){
        log.info("查询所有员工");
        return Result.success(empService.list());
    }
}
